package com.bosicen.crm.dao.sysmanage;

import java.util.List;


import org.springframework.stereotype.Component;
import com.bosicen.crm.dao.HibernateDao;
import com.bosicen.crm.dao.entity.ProductSery;
import com.bosicen.crm.tools.Page;

/**
 * 商品系列
 * @author tigerlei
 *
 */
@Component("productSeryDao")
@SuppressWarnings("unchecked")
public class ProductSeryDao extends HibernateDao<ProductSery, Integer> {

	/****
	 * 查询列表
	 * @param id
	 * @return
	 */
	
	public List<ProductSery> findProductSeryList(ProductSery sery){
		StringBuilder sb=new StringBuilder();
		sb.append("from ProductSery where  companyid=? ");
		if(sery.getPid()>0) sb.append(" and pid=").append(sery.getPid());
		sb.append(" order by id asc ");
		return this.getSession().createQuery(sb.toString()).setParameter(0, sery.getCompanyid()).list();
	}
	
	/**
	 * 按ID查询
	 * @param id
	 * @return
	 */
	public ProductSery findProductSeryById(int id){
		return this.get(id);
	}
	
	/***
	 * 删除
	 * @param c
	 */
	public void delProductSery(ProductSery c){
		//this.getSession().createQuery(" delete from ProductSery where id=").setParameter(0,c.getId()).executeUpdate();
		this.delete(c.getId());
	}
	
	/**
	 * 保存
	 */
	public void saveOrUpdate(ProductSery productSery){
		this.getSession().saveOrUpdate(productSery);
	}
	
	/**
	 * 
	 * @param page
	 * @param companyid
	 * @return
	 */
	public Page findProductSery4Page(Page page,int companyid){
		return this.findPage(page, " from ProductSery where companyid=?  order by id desc", companyid);
	}
	
}
